package main.Trees;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;
import java.io.IOException;

public class OpenProjectTreeRender extends DefaultTreeCellRenderer {

    public OpenProjectTreeRender() {}

    public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {

        super.getTreeCellRendererComponent(
                tree, value, sel,
                expanded, leaf, row,
                hasFocus);

        if (value.toString().equals("Primavera P6 Structure")) {
            try {
                Image iconRoot = ImageIO.read(getClass().getResource("images/prima.png"));
                setIcon(new ImageIcon(iconRoot));
            } catch (IOException e) {
                e.printStackTrace();
            }
            //setToolTipText("This book is in the Tutorial series.");
        }

        if (!value.toString().equals("Primavera P6 Structure") && !leaf) {
            try {
                Image iconRoot = ImageIO.read(getClass().getResource("images/EPS.gif"));
                setIcon(new ImageIcon(iconRoot));
            } catch (IOException e) {
                e.printStackTrace();
            }
            //setToolTipText("This book is in the Tutorial series.");
        }

        if (leaf) {
            try {
                Image iconProject = ImageIO.read(getClass().getResource("images/project.gif"));
                setIcon(new ImageIcon(iconProject));
            } catch (IOException e) {
                e.printStackTrace();
            }
}
        return this;
        }
}
